package gui;
import java.awt.Color;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIDefaults;
import javax.swing.table.TableCellRenderer;

import logic.file.IFile;

//TODO raczej powinno dziedziczyć po label
//sposobem na pozbycie sie lini grid jest chyba tylko dziedziczenie i przedefiniowania metody getIntercellSpacing by bylo 0,0
//ikony wyciagane z OSa - jak zakladki FF
public class FileNameCellRenderer implements TableCellRenderer {
	
	static final Icon fileIcon = new ImageIcon("./images/icons/fileIcon.gif");
	static final Icon dirIcon = new ImageIcon("./images/icons/dirIcon.gif");
	UIDefaults defaults = javax.swing.UIManager.getDefaults();
	
	FileNameCellRenderer() {
		System.out.println("FileNameCellRender");
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int col) {
		JLabel label = new JLabel( (String)value );
		label.setOpaque(true);
		if (isSelected) {
			label.setBackground(defaults.getColor("Table.selectionBackground"));
		}
		if ( ( (IFile)( (FilesTableModel)table.getModel() ).getRow(row) ).isDirectory() ) {
			label.setIcon(dirIcon);
		} else {
			label.setIcon(fileIcon);
		}
		label.setBorder(BorderFactory.createEmptyBorder());
		return label;
	}

}
